package com.douleka.curd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.douleka.curd.entity.SupplyProduct;
import com.douleka.curd.mapper.SupplyProductMapper;
import com.douleka.curd.service.ISupplyProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.douleka.curd.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Stream;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dai
 * @since 2024-03-20
 */
@Service
public class SupplyProductServiceImpl extends ServiceImpl<SupplyProductMapper, SupplyProduct> implements ISupplyProductService {

    @Autowired
    private SupplyProductMapper supplyProductMapper;

    //获取面值和地区
    @Override
    public Result<Object> getAreaAndFace(Integer cardOperatorId) {
        QueryWrapper<SupplyProduct> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("DISTINCT area,face").eq("product_type",cardOperatorId);
        List<SupplyProduct> supplyProducts = supplyProductMapper.selectList(queryWrapper);
//        List<String> area = new ArrayList<>();
        LinkedHashSet<String> area = new LinkedHashSet<>();
        LinkedHashSet<String> face = new LinkedHashSet<>();
//        List<String> face = new ArrayList<>();
        for (SupplyProduct supplyProduct : supplyProducts) {
            area.add(supplyProduct.getArea());
            face.add(supplyProduct.getFace().toString());
        }
        Map<String,Object> map = new HashMap<>();
        map.put("area",area);
        map.put("face",face);
        return new Result<>("200","success",map);
    }
}
